﻿
using WCYCReader;
using WCYCReader.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using WCYCReader.Utility;

namespace WCYCReader.ViewModels
{
    public class MarkerInfoList_VM
    {
        public ObservableCollection<BookMarkerList_M> _T_MarkerInfoList;

        public void Add_MarkerInfoList(object indexItem)
        {
            this.T_MarkerInfoList_VM().Insert(0, indexItem as BookMarkerList_M);
            SettingHelper.SaveInToSettings(App.ReaderFileName + "markerList", new List<BookMarkerList_M>(this.T_MarkerInfoList_VM()));
        }

        public void Delete_MarkerInfoList(object indexItem)
        {
            this.T_MarkerInfoList_VM().Remove(indexItem as BookMarkerList_M);
            if (this.T_MarkerInfoList_VM().Count == 0)
            {
                SettingHelper.DeleteSettings(App.ReaderFileName + "markerList");
            }
            else
            {
                SettingHelper.SaveInToSettings(App.ReaderFileName + "markerList", new List<BookMarkerList_M>(this.T_MarkerInfoList_VM()));
            }
        }

        public ObservableCollection<BookMarkerList_M> T_MarkerInfoList_VM()
        {
            if ((this._T_MarkerInfoList == null) && SettingHelper.IsSettings(App.ReaderFileName + "markerList"))
            {
                this._T_MarkerInfoList = new ObservableCollection<BookMarkerList_M>((List<BookMarkerList_M>)SettingHelper.GetValueFromSettings(App.ReaderFileName + "markerList"));
            }
            return this._T_MarkerInfoList;
        }
    }
}

